package com.open.capacity.notice.statemachine.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.open.capacity.notice.enums.SendJobStatusChangeEnum;

@Component
public class JobActionFactory {

	@Resource
	private List<JobStateAction<?>> actions;

	public JobStateAction<?> getAction(SendJobStatusChangeEnum event) {
		for (JobStateAction<?> action : actions) {
			if (action.event() == null) {
				throw new IllegalArgumentException("event 返回值不能为空：" + action.getClass().getSimpleName());
			}
			if (action.event().equals(event)) {
				return action;
			}
		}
		return null;
	}
}
